////#include<stdio.h>
////
////struct Stu{
////	char name[20];
////	int age;
////	int height;
////	int weight;
////};
////int main()
////{
////	struct Stu s={"feng",19,185,62};
////	printf("%s",s.name ) ;
////	return 0;
////}
//#include<stdio.h>
//#pragma pack(2)
//struct Stu{
//	char a;
//	int c;
//	char b;
//};
//
//int main()
//{
//	printf("%d",sizeof(struct Stu));
//	return 0;
//}
#include<stdio.h>

struct stu{
    char name[11];
    char no[11];
    int grade;
};
int main ()
{
    int n=0;
    scanf("%d",&n);
    int i=0;
    struct stu s[n];
    for(i=0;i<n;i++){
        scanf("%s %s %d",&s[i].name,&s[i].no,&s[i].grade);
    }
    int max=101;
    int x1=0;
    int min=-1;
    int x2=0;
    for(i=0;i<n;i++){
        if (max>s[i].grade){
            max=s[i].grade;
            x1=i;
        }
        if (min<s[i].grade){
            min=s[i].grade;
            x2=i;
        }
    }
    printf("%s %s",s[x1].name,s[x1].no);
    printf("%s %s",s[x2].name,s[x2].no);
    return 0;
}
